
// <copyright file="ControlContentPlaceHolder.cs" company="Subhadra Software Solutions">
//   
// </copyright>
// <summary>
//   Defines the ControlContentPlaceHolder type.
// </summary>

namespace SubhadraSolutions.Sharp.Utils.Web
{
    using System.Web.UI;

    /// <summary>
    /// </summary>
    public class ControlContentPlaceHolder : Control
    {
        #region Methods

        /// <summary>
        /// Sends server control content to a provided <see cref="T:System.Web.UI.HtmlTextWriter"/> object, which writes the
        ///     content to be rendered on the client.
        /// </summary>
        /// <param name="writer">
        /// The <see cref="T:System.Web.UI.HtmlTextWriter"/> object that receives the server control content.
        /// </param>
        protected override void Render(HtmlTextWriter writer)
        {
            ControlContent found = null;
            foreach (Control c in this.NamingContainer.NamingContainer.Controls)
            {
                var search = c as ControlContent;
                if (search != null && search.ControlContentPlaceHolderId.Equals(this.ID))
                {
                    found = search;
                    break;
                }
            }

            if (found != null)
            {
                // write content of the ContentControl
                found.RenderControl(writer);
            }
            else
            {
                // use default content
                base.Render(writer);
            }
        }

        #endregion Methods
    }
}
